import { ui } from "../../ui/layaMaxUI";
import EffectUtil from "../../core_wq/utils/EffectUtil";
import Game from "../../core_wq/game/Game";
import GameCameraNum from "../../core_wq/game/GameCameraNum";
import MainUI from "./MainUI";
import GameEvent from "../../core_wq/game/GameEvent";
import LayerManager from "../../core_wq/manager/LayerManager";
import { GameStateType } from "../../core_wq/game/GameStateType";
import PlayerScript from "../../core_wq/component/PlayerScript";
import TopGoldView from "./TopGoldView";
import TopLevelView from "./TopLevelView";
import GameStageHpView from "./GameStageHpView";
import LeftView from "./LeftView";
import RightView from "./RightView";
import SignView from "../sign/SignView";




export default class MainScene extends Laya.Sprite {

  private _mainUI: MainUI;

  private _gameStageHpView: GameStageHpView;

  private _topGoldView: TopGoldView;

  public get mainUI() {
    return this._mainUI;
  }

  public get gameStageHpView() {
    return this._gameStageHpView;
  }

  public get topGoldView() {
    return this._topGoldView;
  }

  constructor() {
    super();
    this._mainUI = new MainUI();
    this.addChild(this._mainUI);

    this.addChild(Game.footLayer);


    var scene: Laya.Scene3D = this.addChild(new Laya.Scene3D()) as Laya.Scene3D;
    scene.addChild(Game.layer3d);
    this.addChild(Game.hpLayer);
    Game.scene3d = scene;

    var camera: Laya.Camera = (scene.addChild(new Laya.Camera(0, 0.1, 100))) as Laya.Camera;
    Game.cameraNum = new GameCameraNum(-45, 10);
    camera.transform.translate(new Laya.Vector3(0, Game.cameraNum.y, Game.cameraNum.z));
    camera.transform.rotate(new Laya.Vector3(Game.cameraNum.a, 0, 0), true, false);

    camera.orthographicVerticalSize = 10 * Laya.stage.height / Laya.stage.width;

    camera.orthographic = true;
    Game.camera = camera;

    Laya.Matrix4x4.multiply(Game.camera.projectionMatrix, Game.camera.viewMatrix, Game.projectViewMat);


    camera.clearFlag = Laya.BaseCamera.CLEARFLAG_DEPTHONLY;



    var directionLight: Laya.DirectionLight = scene.addChild(new Laya.DirectionLight()) as Laya.DirectionLight;
    directionLight.color = new Laya.Vector3(0.6, 0.6, 0.6);
    directionLight.transform.worldMatrix.setForward(new Laya.Vector3(1, -1, 0));



    Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.onMouseDown);
    Laya.stage.on(Laya.Event.MOUSE_UP, this, this.onMouseUp);


    this._topGoldView = new TopGoldView()
    this.addChild(this._topGoldView);
    this.addChild(new TopLevelView());
    this._gameStageHpView = new GameStageHpView()
    this.addChild(this._gameStageHpView);
    this.addChild(new RightView());
    this.addChild(new LeftView());

    this.addChild(Game.flyLayer);
    this.checkSign();
  }

  checkSign() {
    if (Game.hero.playerData.preSignTime === 0) {
      this.addChild(new SignView());
      return;
    }
    let preSignDate = new Date(Game.hero.playerData.preSignTime);
    preSignDate.setHours(0, 0, 0, 0);
    let today = new Date(Laya.Browser.now());
    today.setHours(0, 0, 0, 0);
    // console.log(today.getTime());
    // console.log(preSignDate.getTime());
    if ((today.getTime() - preSignDate.getTime()) > 86400000) {
      this.addChild(new SignView());
    }

  }



  onMouseDown() {
    Game.isPress = true;
  }

  onMouseUp() {
    Game.isPress = false;
  }







}